<?php
$smarty->configLoad($lang . '/options.module.php');
$language = parse_ini_file($lang . '/breadcrumb.module.php', true);
$breadcrumb = $language['options'];

$sql = 'SELECT * FROM '.DB_CMS.'.website_access_levels';
$dbh = $connection->prepare($sql);
$dbh->execute();
foreach($dbh->fetchAll(PDO::FETCH_ASSOC) as $row) {
    $value[] = $row;
}
$smarty->assign('value', $value);

$sql = 'SELECT * FROM '.DB_CMS.'.website_access_levels';
$dbh = $connection->query($sql);
$i = 1;
$access = '';
foreach($dbh->fetchAll(PDO::FETCH_ASSOC) as $row) {
	$access .= '<option value="'.$row['access_level'].'">'.$row['title'].'</option>'; 
	$json[$i] = $row['title'];
	$i++;
}
$json_rights = json_encode($json);
$smarty->assign('json_rights', $json_rights);
$smarty->assign('access', $access);
if(isset($_POST['submit'])) {
	$main->logAction($_SESSION['id'], 'access_level');
    $sql = 'INSERT INTO '.DB_CMS.'.website_access_levels (title, access_level) VALUES (:title, :access_level)';
    $dbh = $connection->prepare($sql);
    $dbh->bindValue(':title', $_POST['title']);
    $dbh->bindValue(':access_level', $_POST['access']);
    $dbh->execute();
    $main->jqmodal('addet');
    echo '<meta http-equiv="refresh" content="5; URL=index.php?mod=options&page=access">';

}

$template = 'options/access.tpl';
?>